
import request from '@/services';
import { sm2 } from 'sm-crypto-v2';

export const verityService = {
    publicKey: (funcId: string) => request.get('/verity/getPublicKey?funcId=' + funcId),
    imageCode: (funcId: string) => request.get('/verity/imageCode?funcId=' + funcId),
};

export function sm2Encrypt(data: any, PUBLIC_KEY: any) {
    const cipherMode = 1
    const result = sm2.doEncrypt(data, PUBLIC_KEY, cipherMode)
    return "04" + result
}

export function sm2Decrypt(data: any, PRIVATE_KEY: any) {
    const cipherMode = 1
    if (data.startsWith("04")) {
        data = data.slice(2); // 删除前两个字符
    }
    const result = sm2.doDecrypt(data, PRIVATE_KEY, cipherMode)
    return result;
}
export default verityService;